home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freaks Macintosh Archive
/
Freaks Macintosh Archive.bin
/
Freaks Macintosh Archives
/
Hacking & Misc
/
UNIX Cracking
/
MacCracSource.sit
/
MacCrac.source
/
Source
/
Mac Environment.c
< prev
next >
Wrap
Text File
|
1995-02-08
|
6KB
|
283 lines
/*****
CracMac Environment
*****/
#include "Traps.h"
#include "crack.h"
#include <displays.h>
#include <sound.h>
#define NIL 0L
#define MENUNUM 128 /* resedit ID of menu */
#define ABOUTDI 128 /* resedit ID of the About Dialog */
#define SETTINGSDI 129 /* resedit ID of the New Game Dialogue */
#define APPLEM 128 /* apple menu */
#define ABOUTI 1 /* the about Item */
#define FILEM 129 /* file menu */
#define QUITI 1 /* the quit item */
#define EDITM 130 /* the edit menu */
#define CUTI 1
#define COPYI 2
#define PASTEI 3
#define CLEARI 4
#define CRACKM 131 /* crack menu */
#define DOITI 1
#define SETTINGSI 2
#define HELPI 3
#define FOREGROUNDW 128 /* the foreground window*/
static const char kEnter = (char) 0x03;
static const char kReturn = (char) 0x0D;
extern DoIt();
extern SysLog();
extern fcrypt();
extern Log();
void closeForeground()
{
DisposeWindow(FrontWindow());
}
void initForeground()
{
WindowPtr theWindow;
theWindow = GetNewWindow (FOREGROUNDW, NIL, (WindowPtr) -1);
SetPort(theWindow);
TextMode (srcCopy);
TextSize(10);
if (foreground_bool == TRUE)
SysLog("MacCrac Session Started. No passwords guessed.");
ForeColor(blackColor);
MoveTo(0,10);
}
void DoSettings()
{
DialogPtr SettingsDialog;
short itemHit;
EventRecord theEvent;
short itemType;
Handle itemHandle;
Rect itemRect;
SettingsDialog = GetNewDialog(SETTINGSDI, NIL, (WindowPtr) -1);
/* load in old values - I'm using a new dialog every time... */
GetDialogItem(SettingsDialog, 1, &itemType, &itemHandle, &itemRect);
SetControlValue((ControlHandle)itemHandle, foreground_bool);
GetDialogItem(SettingsDialog, 2, &itemType, &itemHandle, &itemRect);
SetControlValue((ControlHandle)itemHandle, verbose_bool);
GetDialogItem(SettingsDialog, 3, &itemType, &itemHandle, &itemRect);
SetControlValue((ControlHandle)itemHandle, recover_bool);
do {
ModalDialog(NIL, &itemHit);
switch (itemHit)
{
case 1:
GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle,
&itemRect);
foreground_bool = GetControlValue((ControlHandle)itemHandle);
foreground_bool = 1 - foreground_bool;
SetControlValue((ControlHandle)itemHandle, foreground_bool);
break;
case 2:
GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle,
&itemRect);
verbose_bool = GetControlValue((ControlHandle)itemHandle);
verbose_bool = 1 - verbose_bool;
SetControlValue((ControlHandle)itemHandle, verbose_bool);
break;
case 3:
GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle,
&itemRect);
recover_bool = GetControlValue((ControlHandle)itemHandle);
recover_bool = 1 - recover_bool;
SetControlValue((ControlHandle)itemHandle, recover_bool);
break;
}
} while (itemHit != 4);
DisposeDialog(SettingsDialog);
}
/****
This initializes everything.
****/
void InitMac(void)
{
/*DialogPtr (AboutDialog); */
InitGraf(&qd.thePort);
InitWindows();
InitDialogs(NULL);
/* AboutDialog = GetNewDialog(ABOUTDI, NIL, (WindowPtr) -1); */
InitFonts();
FlushEvents(everyEvent - osMask - diskMask, 0);
InitMenus();
TEInit();
InitCursor();
MaxApplZone();
MoreMasters();
/* DisposeDialog(AboutDialog); */
}
void do_menu(void)
{
Handle menuBar;
menuBar = GetNewMBar(MENUNUM);
SetMenuBar(menuBar);
DisposHandle(menuBar);
AddResMenu(GetMHandle(APPLEM), 'DRVR'); /*Add DA names to Apple menu */
/* AdjustMenus(); */
DrawMenuBar();
}
/* ShowAbout - shows the about dialogue box.. a modal dialogue */
void ShowAbout(void)
{
DialogPtr AboutDialog;
short itemHit;
SndChannelPtr theSoundChannelP = NIL;
Handle theSoundH = NIL;
OSErr err;
AboutDialog = GetNewDialog(ABOUTDI, NIL, (WindowPtr) -1);
theSoundH = GetResource('snd ', 128);
if (theSoundH != nil) {
err = SndNewChannel(&theSoundChannelP, sampledSynth, initMono,
nil);
if (err == noErr)
SndPlay(theSoundChannelP, (SndListHandle)theSoundH, true);
}
ModalDialog(NIL, &itemHit);
SndDisposeChannel(theSoundChannelP, true);
theSoundChannelP = nil;
ReleaseResource(theSoundH);
theSoundH = nil;
DisposeDialog(AboutDialog);
}
/* HandleMenu -- put the menu choices here
*/
void HandleMenu(long mselect)
{
int menuID = HiWord(mselect);
int menuItem = LoWord(mselect);
Str255 name;
GrafPtr savePort;
switch (menuID)
{
case APPLEM:
if (menuItem == ABOUTI) { ShowAbout(); break;}
GetPort(&savePort);
GetItem(GetMHandle(APPLEM), menuItem, name);
(void) OpenDeskAcc(name);
SetPort(savePort); /* run the DA and return to the prog */
break;
case FILEM:
if (menuItem == QUITI) ExitToShell();
break;
case CRACKM:
if (menuItem == DOITI) DoIt();
if (menuItem == SETTINGSI) DoSettings();
break;
}
}
/* HandleMouseDown takes a mousepress and does whatever it should-- in this case,
the menu bar stuff */
void HandleMouseDown (EventRecord *theEvent)
{
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch(windowCode)
{
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
HandleMenu(MenuSelect(theEvent->where));
break;
}
}
/* Handle Event - does the events */
void HandleEvent(void)
{
int ok;
EventRecord theEvent;
HiliteMenu(0);
SystemTask();
ok = GetNextEvent (everyEvent, &theEvent);
if (ok)
switch (theEvent.what)
{
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
case updateEvt:
case activateEvt:
break;
}
}